Source code for /engineering/webperf/slave-v4[j1.2]/HTTPCmdRead.javaOriginal file HTTPCmdRead.java
   1 import java.net.*;
   2 import java.io.*;
   3 import java.util.*;
   4 
   5 public class HTTPCmdRead extends Thread {
   6    private HTTPRequest request = null;
   7    private Connection  client;
   8    private CmdQueue    queue;
   9    private Command     myCommand;
  10    
  11    public HTTPCmdRead(Connection client, CmdQueue  c) {      
  12       this.client = client;
  13 	this.queue  = c;
  14 	myCommand   = new Command();
  15 
  16       try {
  17          request = new HTTPRequest(client.getInputStream());
  18       } catch (NullPointerException e) {
  19          System.out.println(e);
  20       }
  21       
  22       setDaemon(true);
  23    }
  24    
  25    public void run() {
  26       Hashtable params;
  27       String    c, i, l, s;
  28 	int 	    cmd = Command.cmdNULL;
  29       
  30 	// Let the httprequest object read the instream and then parse it.
  31 	// Stuff into a command an enqueue it.
  32       try {	
  33 	   request.read();
  34 
  35          params = CGI.splitVars(request.content());
  36 
  37          c = (String) params.get("command");
  38          i = (String) params.get("integer");
  39          l = (String) params.get("long");
  40          s = (String) params.get("string");
  41 
  42 	   if (c.equals(Command.cmdTextSTOP)) cmd = Command.cmdSTOP;
  43 	   else if (c.equals(Command.cmdTextPAUSE)) cmd = Command.cmdPAUSE;
  44 	   else if (c.equals(Command.cmdTextNEW))   cmd = Command.cmdNEW;
  45 	   else if (c.equals(Command.cmdTextTARGET)) cmd = Command.cmdTARGET;
  46 	   else if (c.equals(Command.cmdTextGETLOG)) cmd = Command.cmdGETLOG;
  47 	   else if (c.equals(Command.cmdTextGO))     cmd = Command.cmdGO;
  48 	   else if (c.equals(Command.cmdTextPING))   cmd = Command.cmdPING;
  49 	   else cmd = Command.cmdNULL;
  50 
  51 
  52 	   myCommand.setCommand(cmd,Integer.parseInt(i),Long.parseLong(l),s,
  53 				      client,request.protocol());	
  54 
  55 	   queue.putCommand(myCommand);
  56           
  57       } catch (Exception e) {
  58 			
  59 	   // Something REAL bad happened.  Return something to the sender, and
  60 	   // let the connection die.  Do not enqueue a command.	
  61 	   myCommand.setCommand(0,0,0," ",client,request.protocol());	  
  62          StringBuffer r = new StringBuffer();
  63 	   r.append("<HTML><HEAD><TITLE>"+Dispatcher.wordError+"</TITLE></HEAD><BODY><H2>MALFORMED OR CORRUPTED COMMAND");
  64 	   r.append("</H2><PRE>Exception = " +  e.getMessage() +
  65 				 "\n" + e.toString() + "</PRE></BODY></HTML>");
  66 	   myCommand.respond(r.toString());
  67          client.close();
  68 	}
  69    }
  70 
  71 }
  72 
  73       
  74 
  75    
  76